﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Mod_ReportManage_frm_SetReportParam : System.Web.UI.Page
{
    public string DateTimeValidator(ArrayList DateTimeArray)
    {
        string strReturnValue = "";

        IEnumerator ienumer = DateTimeArray.GetEnumerator();

        while (ienumer.MoveNext())
        {
            CuTextSelectBox txtbox = (CuTextSelectBox)ienumer.Current;

            if (txtbox.Text.Trim() == "")
            {
                strReturnValue = txtbox.ToolTip + "不能为空！";

                break;
            }
            else
            {
                try
                {
                    DateTime dateTime = DateTime.Parse(txtbox.Text.Trim());
                }
                catch
                {
                    strReturnValue = txtbox.ToolTip + "格式不正确！";

                    break;
                }
            }
        }

        return strReturnValue;
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.hidUrl.Value = this.Page.Request.Params["ReportUrl"].ToString().Trim();
        }
        else
        { 
            this.lblJs.Text = "";
        }
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string strArea = this.txtArea.Text.Trim();

        if (strArea != "")
        {
            //非空验证
            ArrayList txtBoxArray = new ArrayList();
            txtBoxArray.Add(this.txtBeginTime);
            txtBoxArray.Add(this.txtEndTime);

            string strError = this.DateTimeValidator(txtBoxArray);

            if (strError == "")
            {
                string strParam = "1|" + this.txtAreaID.Text.Trim() +"|" + this.txtBeginTime.Text.Trim() + "|" + this.txtEndTime.Text.Trim() + "|" + strArea;
                this.lblJs.Text = "<script>var win = window.open('frm_PrintPage.aspx?ReportUrl=" + this.hidUrl.Value.Trim() + "&Params=" + strParam + "','','top=0, left=0, toolbar=no, menubar=no,scrollbars=no, resizable=yes,location=no, status=no');";
                this.lblJs.Text += "win.moveTo(0,0); win.resizeTo(screen.availWidth,screen.availHeight);</script>";
            }
            else
            {
                this.lblJs.Text = "<script>alert('" + strError + "');</script>"; 
            }
        }
        else
        {
            this.lblJs.Text = "<script>alert('地区不能为空！');</script>";
        }
    }
}
